<?php
/**
 *UserController
 * @author tan bing
 * @date 2021-08-10 14:27
 */


namespace Modules\User\Http\Controllers\Admin;


use Modules\User\Services\Admin\UserLevelServices;
use Modules\User\Services\Admin\UserServices;

class UserController extends AdminBaseController
{
    /**
     * @var UserServices
     * @author tan bing
     */
    public $userServices;

    /**
     * @var UserLevelServices
     * @author tan bing
     */
    public $userLevelServices;

    /**
     * UserController constructor.
     *
     * @param UserServices $userServices
     * @param UserLevelServices $userLevelServices
     * @author tan bing
     * @date 2021-08-10 15:10
     */
    public function __construct(UserServices $userServices, UserLevelServices $userLevelServices)
    {
        $this->userServices = $userServices;
        $this->userLevelServices = $userLevelServices;
        parent::__construct();
    }

    /**
     * 列表页面
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-08-10 15:20
     */
    public function index()
    {
        $info = $this->userLevelServices->getData();
        $user_level = $info['data'];
        return view('user::admin.user.index', compact('user_level'));
    }

    /**
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-08-11 17:08
     */
    public function capital()
    {
        $info = $this->userServices->getUserDetail();
        $param = $this->userServices->getRequestParam();
        return view('user::admin.user.capital', compact('param', 'info'));
    }

    /**
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-08-13 11:08
     */
    public function capitalLog()
    {
        return view('user::admin.user.capital_log');
    }

    /**
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-08-13 11:08
     */
    public function userLog()
    {
        return view('user::admin.user.user_log');
    }

    /**
     * 编辑页面
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-08-10 15:21
     */
    public function edit()
    {
        $info = $this->userServices->getUserDetail();
        $user_level = $this->userLevelServices->getUserLevel();
        return view('user::admin.user.edit', compact('info', 'user_level'));
    }

    public function detail()
    {
        $info = $this->userServices->getUserDetail();
        $user_level = $this->userLevelServices->getUserLevel();
        return view('user::admin.user.detail', compact('info', 'user_level'));
    }

    /**
     * 获取详情.
     *
     * @return mixed
     * @author tan bing
     * @date 2021-07-19 13:42
     */
    public function getDetail()
    {
        $result = $this->userServices->getUserDetail();
        return $this->success($result);
    }

    /**
     * 获取列表.
     *
     * @return array
     * @author tan bing
     * @date 2021-07-19 13:43
     */
    public function getPageData()
    {
        $result = $this->userServices->getPageData();
        return $this->success($result);
    }

    /**
     * 删除.
     *
     * @return mixed
     * @author tan bing
     * @date 2021-07-19 13:46
     */
    public function delete()
    {
        try {
            $result = $this->userServices->deleteUser();
            if(!$result)
                return $this->failed('删除失败');
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }
        return $this->success();
    }

    /**
     * 批量删除.
     *
     * @return mixed
     * @author tan bing
     * @date 2021-07-19 13:46
     */
    public function batchDelete()
    {
        try {
            $result = $this->userServices->batchDeleteUser();
            if(!$result)
                return $this->failed('删除失败');
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }
        return $this->success();
    }

    /**
     * 编辑状态.
     *
     * @return mixed
     * @author tan bing
     * @date 2021-07-19 13:46
     */
    public function editStatus()
    {
        try {
            $result = $this->userServices->editStatus();
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success($result);
    }

    /**
     * 添加|编辑信息.
     *
     * @return mixed
     * @author tan bing
     * @date 2021-07-19 13:41
     */
    public function addAndEditCustomerDetail()
    {
        try {
            $result = $this->userServices->addAndEditUserDetail();
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success($result);
    }

    /**
     * 修改用户资金
     * @return mixed
     * @throws \Throwable
     * @author tan bing
     * @date 2021-08-11 17:44
     */
    public function editUserCapital()
    {
        try {
            $result = $this->userServices->editUserCapital();
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success($result);
    }

}